package com.example.order.controller;

import com.example.order.config.ServiceResponse;
import com.example.order.config.TableServerResponse;
import com.example.order.service.IOrderComplaint;
import com.example.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.Order;
import pojo.OrderComplain;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @Autowired
    private IOrderComplaint orderComplaint;

    @PostMapping("/createorder")
    public Map<String,Object> order(@RequestHeader(value = "userId") String userId,@RequestBody Order order){
        System.out.println(order.getParkingId()+"----------------------"+userId);
        return orderService.createorder(userId,order);
    }

    /**
     * 此处需要根据用户ID查询订单
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/getOrders")
    public TableServerResponse getOrders(@RequestHeader(value = "userId") String userId,Integer page, Integer limit){
        return orderService.getOrders(userId,page,limit);
    }

    //支付
    @RequestMapping("pay.do")
    public ServiceResponse pay(String orderNo) {
        return orderService.pay(orderNo);
    }

    /**
     * 接收支付宝回调请求
     * @param request
     * @return
     */
    @RequestMapping("alipay_callback.do")
    public String alipayCallback(HttpServletRequest request) {
        return orderService.alipayCallbacks(request);
    }

    //轮询订单支付状态
    @RequestMapping("query_order_pay_status.do")
    public ServiceResponse query_order_pay_status(String orderNo){
        return orderService.query_order_pay_status(orderNo);
    }

    //根据订单编号查询订单
    @RequestMapping("getOrderByOrderNumber")
    public ServiceResponse getOrderByOrderNumber(String orderNumber){
        return orderService.getOrderByOrderNumber(orderNumber);
    }

    //提交订单
    @GetMapping("/orderConfirm")
    public ServiceResponse orderConfirm(String orderNumber){
        return orderService.orderConfirm(orderNumber);
    }

    //订单投诉
    @PostMapping("/orderComplaint")
    public ServiceResponse orderComplaint(OrderComplain orderComplain){
        return orderComplaint.orderComplaint(orderComplain);
    }
    //后台根据条件查询订单
    @GetMapping("/queryOrders")
    public TableServerResponse queryOrders(Order order,Integer page, Integer limit){
        return orderService.queryOrders(order,page,limit);
    }
    /**
     * 此处需要根据用户ID查询订单
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/getOrder")
    public TableServerResponse getOrder(Integer page, Integer limit){
        return orderService.getOrder(page,limit);
    }

}
